Imports System.Xml.Serialization

Public Class Association
    Inherits XEntityModelElementWithDocumentationBase

    ''' <summary>Initializes an instance of the <see cref="Association" /> class.</summary>
    ''' <param name="namespace">The <see cref="XNamespace"/> of the new element.</param>
    Public Sub New(ByVal [namespace] As XNamespace)
        MyBase.New("Association", [namespace].ToString())
    End Sub

    ''' <summary>Initializes an instance of the <see cref="Association" /> class.</summary>
    ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
    Public Sub New(ByVal other As XElement)
        MyBase.New(other)
    End Sub

    Private __end As AssociationEndCollection

    <AutoLoad()> _
    <XmlElement("End", GetType(AssociationEnd))> _
    Public ReadOnly Property Ends() As AssociationEndCollection
        Get
            If (__end Is Nothing) Then
                __end = New EdmxEditor.AssociationEndCollection(Me, MyBase.Name.Namespace, "End")
            End If
            Return __end
        End Get
    End Property

    <AutoLoad()> _
    <XmlElement("ReferentialConstraint")> _
    Public Property ReferentialConstraint() As Constraint
        Get
            Return DirectCast(Me.Element(MyBase.Name.Namespace + "ReferentialConstraint"), EdmxEditor.Constraint)
        End Get
        Set(ByVal value As Constraint)
            If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "ReferentialConstraint")) Then
                Throw New ArgumentException("Invalid Element")
            End If
            If (Me.ReferentialConstraint IsNot Nothing) Then
                Me.ReferentialConstraint.Remove()
            End If
            Me.Add(New EdmxEditor.Constraint(value))
        End Set
    End Property

    <XmlAttribute()> _
    Public Shadows Property Name() As String
        Get
            Return Me.@Name
        End Get
        Set(ByVal value As String)
            Me.@Name = value
        End Set
    End Property

End Class
